package com.dac;

import java.util.List;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.Overlay;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button; 

import com.google.android.maps.*;


public class MainActivity extends MapActivity {
	
	
	OnClickListener o = new OnClickListener(){

		@SuppressWarnings("deprecation")
		public void onClick(View v) {
			// TODO Auto-generated method stub
			MapView mv = (MapView)findViewById(R.id.MapView);
			switch(v.getId()){
			case R.id.btnSat:
				mv.setSatellite(true);
				break;
			case R.id.btnStreet:
				mv.setTraffic(false); 
                mv.setSatellite(false); 
                mv.setStreetView(false); 
                break; 
			}
			
			mv.postInvalidateDelayed(2000);
		}};
		Drawable d;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button btnSat = (Button)findViewById(R.id.btnSat);
        Button btnStreet = (Button)findViewById(R.id.btnStreet);
        btnSat.setOnClickListener(o);
        btnStreet.setOnClickListener(o);
        
        MapView view = (MapView)findViewById(R.id.MapView);
        view.setBuiltInZoomControls(true);//Control dieu khien phong to thu nho
        
        d = getResources().getDrawable(R.drawable.icon_man);
        final List<Overlay> overlayList = view.getOverlays();

        
        
        final MapController controller = view.getController();
        LocationManager locationmanager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
        LocationListener listener = new LocationListener(){

			public void onLocationChanged(Location location) {
				GeoPoint GPS = new GeoPoint((int)location.getLatitude()*1000000,(int)location.getLongitude()*1000000);
				OverlayItem overlayItem = new OverlayItem(GPS, "Thi sao", "What's up");
				CustomPinpoint custom = new CustomPinpoint(d,MainActivity.this);
				custom.insertPinpoint(overlayItem);
				overlayList.add(custom);
				controller.setCenter(GPS);
			}

			public void onProviderDisabled(String provider) {
				// TODO Auto-generated method stub
				
			}

			public void onProviderEnabled(String provider) {
				// TODO Auto-generated method stub
				
			}

			public void onStatusChanged(String provider, int status,
					Bundle extras) {
				// TODO Auto-generated method stub
				
			}
        	
        };
        locationmanager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, listener);
    }        
        

    @Override
    protected boolean isLocationDisplayed(){
    	// TODO Auto-generate method stub
    	return false;
    } 

	@Override
	protected boolean isRouteDisplayed() {
		// TODO Auto-generated method stub
		return false;
	}
}
